// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Infrastructure;

/// <summary>
///     <para>
///         Builds the model for a given context. This implementation builds the model by calling
///         <see cref="DbContext.OnModelCreating(ModelBuilder)" /> on the context.
///     </para>
///     <para>
///         This type is typically used by database providers (and other extensions). It is generally
///         not used in application code.
///     </para>
/// </summary>
/// <remarks>
///     <para>
///         The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance
///         is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe.
///         This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />.
///     </para>
///     <para>
///         See <see href="https://aka.ms/efcore-docs-providers">Implementation of database providers and extensions</see>
///         for more information and examples.
///     </para>
/// </remarks>
public class ModelCustomizer : IModelCustomizer
{
    /// <summary>
    ///     Initializes a new instance of the <see cref="ModelCustomizer" /> class.
    /// </summary>
    /// <param name="dependencies">Parameter object containing dependencies for this service.</param>
    public ModelCustomizer(ModelCustomizerDependencies dependencies)
        => Dependencies = dependencies;

    /// <summary>
    ///     Dependencies for this service.
    /// </summary>
    protected virtual ModelCustomizerDependencies Dependencies { get; }

    /// <summary>
    ///     Performs additional configuration of the model in addition to what is discovered by convention. This default implementation
    ///     builds the model for a given context by calling <see cref="DbContext.OnModelCreating(ModelBuilder)" />
    ///     on the context.
    /// </summary>
    /// <param name="modelBuilder">
    ///     The builder being used to construct the model.
    /// </param>
    /// <param name="context">
    ///     The context instance that the model is being created for.
    /// </param>
    public virtual void Customize(ModelBuilder modelBuilder, DbContext context)
        => context.OnModelCreating(modelBuilder);
}
